package org.domeos.framework.api.mapper.domeos.storage;

import org.apache.ibatis.annotations.*;
import org.domeos.framework.api.model.storage.VolumeDeployMap;
import java.util.List;

/**
 * Created by feiliu206363 on 2017/1/20.
 */
@Mapper
public interface VolumeDeployMapper {
    @Insert("INSERT INTO volume_deploy_map" + " (volumeId, deployId, versionId, createTime) values (" +
            " #{item.volumeId}, #{item.deployId}, #{item.versionId}, #{item.createTime})")
    void addVolumeVersionMount(@Param("item") VolumeDeployMap volumeDeployMap);

    @Delete("DELETE FROM volume_deploy_map" + " WHERE deployId=#{deployId}")
    void removeVolumeVersionMapByDeployId(@Param("deployId") int deployId);

    @Delete("DELETE FROM volume_deploy_map" + " WHERE versionId=#{versionId}")
    void removeVolumeVersionMapByVersionId(@Param("versionId") int versionId);

    @Select("SELECT * FROM volume_deploy_map" + " WHERE volumeId=#{volumeId}")
    List<VolumeDeployMap> getMapsByVolumeId(@Param("volumeId") int volumeId);
    
    @Select("SELECT count(*) FROM volume_deploy_map" + " WHERE volumeId=#{volumeId}")
    int getCountMapsByVolumeId(@Param("volumeId") int volumeId);
}
